const baseUrl = 'https://jt.twozii.com/api';

function request(params) {
	return new Promise((resolve, reject) => {
		let header = {};
		if (uni.getStorageSync("sessionid")) {
			header.cookie = uni.getStorageSync("sessionid");
		}
		uni.request({
			...params,
			url: baseUrl + params.url,
			header: header,
			success: (res) => {
				if (res.data.code !== 0) {
					uni.showModal({
						content: res.data.msg
					})
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return;
				}else{
					resolve(res)
				}
			},
			fail: (err) => {
				reject(err)
			},
			complete: (res) => {
				if (res && res.header && res.header['Set-Cookie']) {
					uni.setStorageSync('sessionid', res.cookies ? res.cookies.join(";") : res.header['Set-Cookie']); //保存Cookie到Storage
				}
			}
		})
	})

}

export {
	request
}
